﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


using System;
using System.Collections;
using System.Collections.Generic;
using Tesla.Graphics;

namespace Tesla.Direct3D10.Graphics {
    /// <summary>
    /// Concrete Direct3D10 implementation of <see cref="IEffectAnnotationCollection"/>.
    /// </summary>
    public sealed class D3D10EffectAnnotationCollection : IEffectAnnotationCollection {
        private List<D3D10EffectAnnotation> _annotations;

        /// <summary>
        /// Gets the number of annotations contained in the collection.
        /// </summary>
        public int Count {
            get {
                return _annotations.Count;
            }
        }

        /// <summary>
        /// Gets the annotation specified by its index.
        /// </summary>
        /// <returns>The annotation, if it exists</returns>
        public IEffectAnnotation this[int index] {
            get {
                if(index >= 0 && index < _annotations.Count) {
                    return _annotations[index];
                }
                return null;
            }
        }

        /// <summary>
        /// Gets the annotation specified by its index.
        /// </summary>
        /// <returns>The annotation, if it exists</returns>
        public IEffectAnnotation this[String name] {
            get {
                for(int i = 0; i < _annotations.Count; i++) {
                    IEffectAnnotation anno = _annotations[i];
                    if(anno.Name.Equals(name)) {
                        return anno;
                    }
                }
                return null;
            }
        }

        /// <summary>
        /// Creates a new instance of <see cref="D3D10EffectAnnotationCollection"/>.
        /// </summary>
        internal D3D10EffectAnnotationCollection() {
            _annotations = new List<D3D10EffectAnnotation>();
        }

        /// <summary>
        /// Adds the D3D10 annotation.
        /// </summary>
        /// <param name="anno">The D3D10 annotation.</param>
        internal void Add(D3D10EffectAnnotation anno) {
            _annotations.Add(anno);
        }

        /// <summary>
        /// Returns an enumerator that iterates through the collection.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
        /// </returns>
        public IEnumerator<IEffectAnnotation> GetEnumerator() {
            return (IEnumerator<IEffectAnnotation>) _annotations.GetEnumerator();
        }

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator() {
            return (IEnumerator) _annotations.GetEnumerator();
        }
    }
}
